package com.kunbo.cn.service.impl.core.purchase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.dao.core.purchase.ModulationHistoryDao;
import com.kunbo.cn.dto.ModulationHistoryDto;
import com.kunbo.cn.entity.core.purchase.ModulationHistory;
import com.kunbo.cn.service.core.purchase.ModulationHistoryService;

@Service
public class ModulationHistoryImpl implements ModulationHistoryService{
	
	@Autowired
	private ModulationHistoryDao dao;
	@Autowired
	private JdbcTemplate jdbc;

	@Override
	public boolean save(String uuid, String create_user_id, String taskid, String adjustment_time, double orginal_count,
			double Adjusts, String order_code) {
		// TODO Auto-generated method stub
		ModulationHistory modulation = new ModulationHistory();
		modulation.setUuid(uuid);
		modulation.setCreate_user_id(create_user_id);
		modulation.setTaskid(taskid);
		modulation.setAdjustment_time(adjustment_time);
		modulation.setOrginal_count(orginal_count);
		modulation.setAdjusts(Adjusts);
		modulation.setOrder_code(order_code);
		modulation = dao.save(modulation);
		if(modulation == null)
			return false;
		else
			return true;
	}

	@Override
	public List<ModulationHistoryDto> get(String order_code) {
		// TODO Auto-generated method stub
		List<ModulationHistoryDto> modulation = new ArrayList<ModulationHistoryDto>();
		String sql = "select * from business_modulation_history where order_code = '" + order_code + "'";
		List<Map<String, Object>>  list = jdbc.queryForList(sql);
		for (Map<String, Object> map : list) {
			ModulationHistoryDto dto = new ModulationHistoryDto();
			sql = "select * from sys_user where id = '" + map.get("create_user_id").toString() + "'";
			Map<String, Object> user = jdbc.queryForMap(sql);
			dto.setModulation(map);
			dto.setUser(user);
			modulation.add(dto);
		}
		return modulation;
	}

}
